package com.videri.match.client;

import com.allen_sauer.gwt.dragdrop.client.DragController;
import com.allen_sauer.gwt.dragdrop.client.DragEndEvent;
import com.allen_sauer.gwt.dragdrop.client.drop.DropController;
import com.allen_sauer.gwt.dragdrop.client.drop.SimpleDropController;
import com.allen_sauer.gwt.dragdrop.client.drop.VetoDropException;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class StringBoxDropController extends SimpleDropController {
	private static final String CSS_MATCH_STRINGBOX_ENGAGE = "match-stringbox-engage";
	
	private final SimplePanel dropTarget;
	private final VerticalPanel myInsidePanel;
	
	public StringBoxDropController(SimplePanel dropTarget)
	{
		super(dropTarget);
		this.dropTarget = dropTarget;
		myInsidePanel = new VerticalPanel();
		dropTarget.setWidget(myInsidePanel);
	}

	public void onEnter(Widget reference, Widget draggable, DragController dragController) {
		super.onEnter(reference, draggable, dragController);
		dropTarget.addStyleName(CSS_MATCH_STRINGBOX_ENGAGE);
	}

	public void onLeave(Widget draggable, DragController dragController) {
		super.onLeave(draggable, dragController);
		dropTarget.removeStyleName(CSS_MATCH_STRINGBOX_ENGAGE);
	}

	public DragEndEvent onDrop(Widget reference, Widget draggable, DragController dragController) {
		DragEndEvent dee = super.onDrop(reference, draggable, dragController);
		dropTarget.removeStyleName(CSS_MATCH_STRINGBOX_ENGAGE);
		myInsidePanel.add(draggable);
		return dee;
	}
	
	public Widget[] getDropped() {
		Widget[] ret = new Widget[myInsidePanel.getWidgetCount()];
		for (int i=0;i<ret.length;i++) {
			ret[i] = myInsidePanel.getWidget(i);
		}
		return ret;
	}
}
